<template>
	<view class="page">
		<flowbefore :beflows="beflows" :status="status" :isBtnClick="isBtnClicks" @save="save" @submit="submit" :statusType="statusType">
			<template>
				<view class="padding-bottom-100">
					<form class="flowform">
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>流程标题</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="article.F_FlowTitle" name="F_FlowTitle" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>单号编号</label></view>
								<view class="controlvalue">
									<input type="text" v-model="article.F_BillNo" name="F_BillNo" disabled="true" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext" @tap="flowUrgent">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>紧急程度</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="article.F_FlowUrgent" name="F_FlowUrgent" placeholder="选择" disabled="true" />
								</view>
								<view class="advanceicon iconfont icon-xiangyou"></view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>申请人员</label></view>
								<view class="controlvalue">
									<input type="text" v-model="article.F_ApplyUser" name="F_ApplyUser" disabled="true" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>所属部门</label></view>
								<view class="controlvalue">
									<input type="text" v-model="article.F_Department" name="F_Department" disabled="true" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup">
								<view class="labletitle"><label>申请日期</label></view>
								<view class="controlvalue">
									<input type="text" v-model="article.F_ApplyDate" name="F_ApplyDate" disabled="true" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext margin-top-20">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>用品库存</label></view>
								<view class="controlvalue">
									<input type="text" v-model="article.F_Articles" name="F_Articles" placeholder="输入用品库存" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>用品分类</label></view>
								<view class="controlvalue">
									<input type="text" v-model="article.F_Classification" name="F_Classification" placeholder="输入用品分类" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>用品编号</label></view>
								<view class="controlvalue">
									<input type="text" v-model="article.F_ArticlesId" name="F_ArticlesId" placeholder="输入用品编号" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>单位</label></view>
								<view class="controlvalue">
									<input type="text" v-model="article.F_Company" name="F_Company" placeholder="输入单位" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>数量</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="number" v-model="article.F_EstimatePeople" name="F_EstimatePeople" maxlength="6" placeholder="输入数量"
									 :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist">
							<view class="formgroup  padding-17">
								<view class="labletitletar"><label>申请原因</label></view>
								<view class="controlvalue  uni-textarea">
									<textarea v-model="article.F_ApplyReasons" name="F_ApplyReasons" :disabled="disabled" placeholder="输入" />
									</view>
							</view>
						</view>
					</form>
					<view class="height-100"></view>
				</view>
			</template>
		</flowbefore>
		<w-picker :mode="mode" :pickerList="pickerList" ref="picker" :isSearchShow="isSearchShow"></w-picker>
	</view>
</template>

<script>
	import jnpf from '@/common/js/jnpf.js'
	import helper from '@/common/js/helper.js'
	import graceChecker from '@/common/js/graceChecker.js'
	import wPicker from '@/components/w-picker/w-picker.vue'
	import flowbefore from '@/components/work/flow-before.vue'
	let formRule=[
			{name:"F_FlowTitle",checkType:"notnull",checkRule:"",errorMsg:"输入标题"},
			{name:"F_FlowUrgent", checkType : "notnull", checkRule:"",  errorMsg:"选择紧急程度"},
			{name:"F_EstimatePeople", checkType : "int", checkRule:"0,6",  errorMsg:"数量应为1-6个字符"},
		];
	export default {
		data() {
			return {
				mode:'',//底部弹窗分类
				isSearchShow:false,
				disabled:false,//启用
				status:'',//流程状态
				beflows:{
					operstate:"",
					processId:''
				},
				article:{
					F_BillNo:'',
					F_FlowUrgent:'',
					F_FlowTitle:jnpf.userInfo().realName+'的用品入库申请表',
					F_ApplyUser:jnpf.userInfo().realName,
					F_Department:jnpf.organizeData(jnpf.userInfo().organizeId).F_FullName,
					F_ApplyDate:helper.toDate(new Date, 'yyyy-MM-dd'),
					F_EstimatePeople:''
				},
				isBtnClicks:false,
				pickerList:[],
				urgentList:[{
					label: "普通",
					value:"1"
				},
				{
					label: "重要",
					value:"2"
				},
				{
					label: "紧急",
					value:"3"
				}],
				statusType:''
			}
		},
		onLoad(e) {
			/* 工作区进入状态 */
			let statusType = uni.getStorageSync("type")
			this.statusType = statusType
			/* 工作区进入状态 End*/
			let flowInfo= JSON.parse(e.flowInfo);
			this.beflows.operstate=flowInfo.operstate;
			if(flowInfo.operstate =='add'){
				this.article.F_FlowId=flowInfo.id;
				this.status = 0;
				this.article.F_FlowUrgent=helper.getSpinnerNew(this.urgentList,'1');
				helper.ajax({
					url: '/api/System/BillRule/BillNumber/WF_ArticlesWarehousNo',
					success: res => {
						this.article.F_BillNo=res.data.data;
					}
				});
			}
			if(flowInfo.operstate=='info'){
				this.disabled=flowInfo.disabled;
				this.beflows.processId=flowInfo.id;
				this.status = flowInfo.status;
				helper.ajax({
					url: '/api/WorkFlowForm/ArticlesWarehous/Info/' + flowInfo.id,
					success: res => {
						let _article=res.data.data;
						this.article = _article;
						this.article.F_FlowUrgent=helper.getSpinnerNew(this.urgentList,_article.F_FlowUrgent);
						this.article.F_ApplyDate=helper.toDate(_article.F_ApplyDate, "yyyy-MM-dd HH:mm");
					}
				});
			}
		},
		methods: {
			flowUrgent(e) {
				if(!this.disabled){
					this.pickerList = this.urgentList;
					this.mode="selector";
					this.$refs.picker.show();
					this.$eventHub.$off('popupmodality');
					this.$eventHub.$on('popupmodality', (data) => {
						this.article.F_FlowUrgent = data.result;
						this.$eventHub.$off('popupmodality');
					});
				}
			},
			submit(e){
				let formData=this.article;
				if (!graceChecker.check(formData,formRule)) {
					helper.msg(graceChecker.error);
					return
				}
				this.isBtnClicks=true;
				formData.F_FlowUrgent=helper.setSpinnerNew(this.urgentList,formData.F_FlowUrgent);
				helper.ajax({
					url: '/api/WorkFlowForm/ArticlesWarehous/Submit',
					method:'POST',
					data:formData,
					success: res => {
						helper.msg(res.data.message, 'success');
						if (this.beflows.operstate=='add') {
							uni.redirectTo({
								url: '../../operate/started/started',
								success: res => {},
								fail: () => {},
								complete: () => {}
							});
						}else{
							uni.navigateBack();
						}
						this.isBtnClicks=false
					}
				});
			},
			save(e){
				let formData=this.article;
				if (!graceChecker.check(formData,formRule)) {
					helper.msg(graceChecker.error);
					return
				}
				this.isBtnClicks=true;
				formData.F_FlowUrgent=helper.setSpinnerNew(this.urgentList,formData.F_FlowUrgent);
				helper.ajax({
					url: '/api/WorkFlowForm/ArticlesWarehous/Save',
					method:'POST',
					data:formData,
					success: res => {
						helper.msg(res.data.message, 'success');
						if (this.beflows.operstate=='add') {					
							uni.redirectTo({
								url: '../../operate/started/started',
								success: res => {},
								fail: () => {},
								complete: () => {}
							});
						}else{
							uni.navigateBack();
						}
						this.isBtnClicks=false
					}
				});
			},
		},
		components: {
			wPicker,
			flowbefore,
		}
	}
</script>

<style>
	.required{
		color: red;
	}
</style>
